package com.sduept.nwld.dataview.controller.message;

import com.sduept.bigdata.web.jsf.controller.AbstractController;
import com.sduept.core.dao.SuperDAO;
import com.sduept.message.entity.Message;
import org.springframework.beans.factory.annotation.Autowired;

import javax.annotation.PostConstruct;
import javax.inject.Named;
import javax.faces.view.ViewScoped;

@Named
@ViewScoped
public class LookMessageController extends AbstractController {

	/**
	 * 
	 */
	private static final long serialVersionUID = -1021954886125757503L;

	public  static final String libpath = "com.sduept.component.message.model.";

	private Class<? extends Message> T = null;
	@Autowired
	private SuperDAO dao;
	
	private Message message;
	private String type;
	@SuppressWarnings("unchecked")
	@PostConstruct
	public void init(){
		String id = getParameter("id");
		type = getParameter("type");
		if(id!=null && type!=null){
			String cname = libpath+type;
			try {
				T = (Class<? extends Message>) Class.forName(cname);
			} catch (ClassNotFoundException e) {
				e.printStackTrace();
			}
			message= dao.findById(id, T);
		}
	}
	public Message getMessage() {
		return message;
	}
	public String getType() {
		return type;
	}
	public void setType(String type) {
		this.type = type;
	}
}
